package com.zqwh.storemonitor.service;

import android.content.Context;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.igexin.sdk.GTIntentService;
import com.igexin.sdk.message.GTCmdMessage;
import com.igexin.sdk.message.GTNotificationMessage;
import com.igexin.sdk.message.GTTransmitMessage;
import com.zqwh.storemonitor.domain.GeTuiMsg;
import com.zqwh.yj.sdk.utils.LogUtils;
import com.zqwh.yj.sdk.utils.RxBus;

import static com.zqwh.storemonitor.StoreMonitorApplication.sGeTuiCid;

public class GeTuiPushIntentService extends GTIntentService {
    @Override
    public void onReceiveServicePid(Context context, int i) {

    }

    @Override
    public void onReceiveClientId(Context context, String clientid) {
        LogUtils.logout("onReceiveClientId -> " + "clientid = " + clientid);
        sGeTuiCid = clientid;
    }

    @Override
    public void onReceiveMessageData(Context context, GTTransmitMessage msg) {
        byte[] payload = msg.getPayload();

        if (payload == null) {
            LogUtils.debug("receiver payload = null");
        }else {
            String msgStr = new String(payload);
            Gson gson = new Gson();
            GeTuiMsg geTuiMsg = gson.fromJson(msgStr, new TypeToken<GeTuiMsg>(){}.getType());
            RxBus.getInstance().post(geTuiMsg);
        }
    }

    @Override
    public void onReceiveOnlineState(Context context, boolean b) {

    }

    @Override
    public void onReceiveCommandResult(Context context, GTCmdMessage gtCmdMessage) {

    }

    @Override
    public void onNotificationMessageArrived(Context context, GTNotificationMessage gtNotificationMessage) {

    }

    @Override
    public void onNotificationMessageClicked(Context context, GTNotificationMessage gtNotificationMessage) {

    }
}
